package com.yfore.jfinal.alidayu.plugin;

import com.jfinal.plugin.IPlugin;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;

/**
 * 阿里大于短信插件
 * @author farmer
 *
 */
public class AlidayuPlugin implements IPlugin{
	
	//TaobaoClient
	TaobaoClient client = null;
	//请求地址
	private String url;
	//应用的AppKey
	private String appkey;
	//secret
	private String secret;
	//格式
	private String format;
	
	/**
	 * 构造个阿里大于插件
	 * @param url
	 * 		请求地址
	 * @param appkey
	 * 		TOP分配给应用的AppKey
	 * @param secret
	 * 		App Secret
	 */
	public AlidayuPlugin(String url,String appkey ,String secret) {
		this(url,appkey,secret,"xml");
	}
	
	/**
	 * 
	 * @param url
	 * 		请求地址
	 * @param appkey
	 * 		TOP分配给应用的AppKey
	 * @param secret
	 * 		App Secret
	 * @param format
	 * 		响应格式，默认xml，可选json
	 */
	public AlidayuPlugin(String url,String appkey ,String secret,String format) {
		this.url = url;
		this.appkey = appkey;
		this.secret = secret;
		this.format = format;
	}
	
	@Override
	public boolean start() {
		client = new DefaultTaobaoClient(url, appkey, secret,format);
		AlidayuKit.init(client);
		return true;
	}
	
	@Override
	public boolean stop() {
		return true;
	}
	
	public static void main(String[] args) {

	}
	
}
